import { Toast } from 'mint-ui';
let qs = require('qs');
let scrollTop;

export default {
  qs: qs,
  whenToast: (before, toastOptions, after, holdStill) => {
    before();

    let toast = Toast(toastOptions);

    setTimeout(() => {

      if (toastOptions.duration === -1) {
        toast.close();
      }

      after();
    }, holdStill)
  },
  clickIdDom: (id) => {
    document.getElementById(id).click();
  },
  formattedDate: (date) => {
    return {
      year: date.getFullYear(),
      month: date.getMonth() + 1 < 10 ?  '0' + (date.getMonth() + 1) : date.getMonth() + 1,
      day: date.getDate() < 10 ? '0' + date.getDate() : date.getDate()
    }
  },
  fixedTheBG: (newVal, id) => {
    let app = document.getElementById('app');
    if (newVal === false) {
      app.style.position = 'static';
      document.body.scrollTop = scrollTop;
    } else {
      scrollTop = document.body.scrollTop;
      app.style.position = 'fixed';
    }
  },
  getLastFour: (before) => {
    return before.slice(-4);
  }
}
